/*
 * This file is part of b.AMP.
 *
 * b.AMP is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * b.AMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with b.AMP.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __BAMP_MESSAGE_TARGET_HPP__
#define __BAMP_MESSAGE_TARGET_HPP__

#include "message_ack.hpp"

namespace bamp
{

    /*
     * Forward declarations.
     */
    class MessageSource;
    class Message;


    /**
     * A message target is any class that can receive and handle messages.
     * Since the target could handle messages asynchronously, it must return
     * a message acknowledgement object that the caller can use to know
     * when the message has finished being processed.
     */
    class MessageTarget {

    public:

        /**
         * Constructor.
         */
        MessageTarget() {}

        /**
         * Virtual destructor.
         */
        virtual ~MessageTarget() {}


        /**
         * Handle a message by calling all the handlers registered for its
         * type using connect(). The message acknowledgement object will be
         * notified when the message has finished being handled.
         * @param message the message
         * @param ack   message acknowledgement object
         */
        virtual void send(const Message& message, MessageAck ack) = 0;

        /**
         * Dispatch a message to the target. After the call, the message does
         * not have to be valid anymore: the message target must create its
         * own internal copy if it still needs it after the function
         * returns.
         * @param message message to be handled
         * @return      message acknowledgement
         */
        virtual MessageAck send(const Message& message) = 0;

    }; // class MessageTarget

} // namespace bamp

#endif // __BAMP_MESSAGE_TARGET_HPP__
